package com.xxx.video.channel.adapters;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.xxx.video.R;
import com.xxx.video.channel.beans.ChanelHomeListBean;
import com.xxx.video.channel.config.ChannelFragmentItemClickType;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.adapters.BaseViewHolder;
import com.xxx.video.main.adapters.HomeFragmentGridVideoListAdapter;
import com.xxx.video.main.beans.VideoListBean;

import butterknife.BindView;

public class OtherChannelListAdapter extends BaseRecycleViewAdapter<ChanelHomeListBean.TypeListBean, OtherChannelListAdapter.MyHolder> {


    public OtherChannelListAdapter(@NonNull Context context) {
        super(context);
    }

    @Override
    public MyHolder onCreateDefaultViewHolder(View view, int viewType) {
        return new MyHolder(view);
    }

    @Override
    public int getItemLayout(int viewType) {
        return R.layout.item_other_channel_list;
    }

    @Override
    public boolean isSetBaseItemViewClickListener() {
        return false;
    }

    class MyHolder extends BaseViewHolder {

        @BindView(R.id.tv_item_other_channel_list_title)
        TextView tvItemOtherChannelListTitle;
        @BindView(R.id.rcv_item_other_channel_list_video_list)
        RecyclerView rcvItemOtherChannelListVideoList;
        @BindView(R.id.tv_item_other_channel_list_look_more)
        TextView tvItemOtherChannelListLookMore;

        public MyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData2View(int position) {
            ChanelHomeListBean.TypeListBean typeListBean = getItem(position);
            tvItemOtherChannelListTitle.setText(typeListBean.fName);
            rcvItemOtherChannelListVideoList.setLayoutManager(new GridLayoutManager(context, 2));
            HomeFragmentGridVideoListAdapter homeFragmentGridVideoListAdapter = new HomeFragmentGridVideoListAdapter(context);
            rcvItemOtherChannelListVideoList.setAdapter(homeFragmentGridVideoListAdapter);
            homeFragmentGridVideoListAdapter.setData(typeListBean.contentList);
            homeFragmentGridVideoListAdapter.setOnItemClickListener((OnItemClickListener<VideoListBean>) (videoListBean, position1, type) -> {
                if (onItemClickListener != null) {
                    ChanelHomeListBean.TypeListBean typeListBean2 = new ChanelHomeListBean.TypeListBean();
                    typeListBean2.fId = videoListBean.fId;
                    onItemClickListener.onItemClick(typeListBean2, 0, ChannelFragmentItemClickType.CHANNEL_FRAGMENT_ITEM_CLICK_TYPE_VIDEO_DETAILS);
                }
            });
            tvItemOtherChannelListLookMore.setOnClickListener(v -> {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(typeListBean, 0, ChannelFragmentItemClickType.CHANNEL_FRAGMENT_ITEM_CLICK_TYPE_START_CHANNEL_LIST);
                }
            });
        }
    }
}
